import { createRouter, createWebHistory } from "vue-router";
import Layout from "@/views/Layout/index.vue";
import Login from "@/views/Loogin/index.vue";
import Home from "@/views/Home/index.vue";
import Category from "@/views/Category/index.vue";
import subCategory from "@/views/subCategory/index.vue";
import Detail from "@/views/Detail/index.vue";
import CartList from "@/views/CartList/index.vue";
import CheckOut from "@/views/CheckOut/index.vue";
import Pay from "@/views/Pay/index.vue";

//createRouter：创建路由实例  createWebHistory：创建哈希模式路由
const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: "/",
            component: Layout,
            children: [
                // 默认二级路由会在一级路由渲染时同步渲染，配置技巧是将其设置为空即可
                {
                    path: "/",
                    component: Home,
                },
                {
                    path: "/category/:id",
                    component: Category,
                },
                {
                    path: "/category/sub/:id",
                    component: subCategory,
                },
                {
                    path: "/detail/:id",
                    component: () => {
                        return Detail;
                    },
                },
                {
                    path: "/cartlist",
                    component: CartList,
                },
                {
                    path: "/checkout",
                    component: CheckOut,
                },
                {
                    path: "/pay",
                    component: Pay,
                },
            ],
        },
        {
            path: "/login",
            component: Login,
        },
    ],
    scrollBehavior() {
        return {
            top: 0,
        };
    },
});

export default router;
